package com.example.thread.d7ThreadTest;

import lombok.Synchronized;

import java.util.List;
import java.util.Random;

public class SendThread extends Thread{
    private List<String> gift;
    private int count;
    public SendThread(List<String> gift,String name) {
        super(name);
        this.gift = gift;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        while (true) {
            synchronized (gift) {
                if(gift.size() < 10) {
                    break;
                }

                Random r = new Random();
                String rs = gift.remove(r.nextInt(gift.size()));
                System.out.println(name+"发出了"+rs);
                count++;
            }
        }
    }
}
